#!/bin/sh
#$Id$
#
#  Examples:
#     nohup copy-VAR-to-var 10 .
#     nohup copy-VAR-to-var 40 ../hydro256e
#
#  Usage:
#     will copy all VAR5 files to var.dat in each proc directory.
#
#  Description:
#     Used for restarting from a given VAR file.
#     Copies all VARx files to var.dat in each proc directory.
#     Run this command from run directory, not data directory.
#     The first argument gives the number of the snapshot.
#     The second argument gives the target directory.
#
#  14-nov-02/axel: coded
#  16-nov-02/axel: enhanced comments

/bin/pwd >> $2/data/copied_from.dir
/bin/date >> $2/data/copied_from.dir

procdirs="`\ls data | grep ^proc `"
echo $procdirs
for proc in $procdirs
do
  echo "cp data/$proc/VAR$1 $2/data/$proc/var.dat"
  cp data/$proc/VAR$1 $2/data/$proc/var.dat
  if [ -e "data/$proc/PVAR$1" ]; then
    echo "cp data/$proc/PVAR$1 $2/data/$proc/pvar.dat"
    cp data/$proc/PVAR$1 $2/data/$proc/pvar.dat
  fi
  if [ -e "data/$proc/SPVAR$1" ]; then
    echo "cp data/$proc/SPVAR$1 $2/data/$proc/spvar.dat"
    cp data/$proc/SPVAR$1 $2/data/$proc/spvar.dat
  fi

done
#
# Some output and a warning.
#
echo "Finished... Remember that you may now have to change the files"
echo "tsnap.dat, move-me.list, moved-files.list and time_series.dat manually!"
